#ifndef     __LOG_UART_H
#define     __LOG_UART_H

#include "../rtos/event_flags.h"


namespace driver {

class LogUart : private utils::NoCopyable {

public:
    static constexpr uint32_t FLAG_DMA_TC = 0x01;

    static constexpr uint32_t WRITE_BUF_SIZE = 64;
    
    void init();

    void printf(const char *format, ...);
    void on_dma_tc() { m_flags.set_flags(FLAG_DMA_TC); }
private:
    static void write_by_dma(const void *buf, uint16_t len);


    char m_write_buf[WRITE_BUF_SIZE];
    rtos::EventFlags m_flags;
};

extern LogUart logUart;

class DebugInfo {

public:
    DebugInfo(const char *info) : begin(osKernelGetTickCount()), func_info(info) {
        logUart.printf("call %s\r\n", info);
    }
    ~DebugInfo() {
        logUart.printf("%s finish elapsed:%dms\r\n", func_info, osKernelGetTickCount() - begin);
    }

private:
    uint32_t begin;
    const char *func_info;
};

#define DEBUG()     DebugInfo __INFO(__func__)

}

#endif
